fix: add SSE backpressure safeguards for slow clients#19493
fix: add SSE backpressure safeguards for slow clients#19493sjawhar wants to merge 1 commit intoanomalyco:devfrom
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Duplicate PRs Found1. #19423 - fix(server): add backpressure to SSE event queues
2. #18538 - fix(opencode): handle client disconnect in SSE event route writes
|
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Note on PR#19423PR#19423 appears to be a duplicate of this PR — both implement the same SSE backpressure safeguard fix for issue #16697. Relationship:
Recommendation: If PR#19423 is already merged, this PR can be closed as duplicate. If not, one should be closed in favor of the other to avoid duplicate commits. |
|
Closing: consolidated into the serve hardening branch on sami. |
Issue for this PR
Fixes #16697
Type of change
What does this PR do?
Adds backpressure to the
AsyncQueueused by SSE endpoints to prevent unbounded memory growth when clients fall behind.Root cause:
AsyncQueuehas no size limit. When an SSE client stalls (slow network, backgrounded tab, stalled proxy),Bus.subscribeAllkeeps pushingJSON.stringify'd events into the queue without bound. In production this caused 187GB RSS.Fix: Add optional
capacityparameter toAsyncQueuewith drop-oldest behavior. When the queue exceeds capacity, oldest items are discarded. Set to 1024 items (~2MB at ~2KB avg event size) for both SSE endpoints. TUI queues remain unbounded since they are 1:1 request/response pairs that never accumulate.The web UI already handles reconnection gracefully (full state reload on
server.connected), so dropped events during a stall are recovered naturally.How did you verify your code works?
Checklist